﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference name="Dimok.Web.UI.JS.JQuery.VSDoc.js" assembly="Dimok.Web.UI" />
/// <reference name="Dimok.Web.UI.JS.JQuery.Extentions.js" assembly="Dimok.Web.UI" />
/// <reference name="Dimok.Web.UI.JS.MSAjaxExtentions.js" assembly="Dimok.Web.UI" />
Type.registerNamespace("Dimok");
Dimok.ProfilerAjax = function() {
Dimok.ProfilerAjax.initializeBase(this);
  this._initProps({_wsPath:'',_pageType:'',_windowTop:0,_windowLeft:0,_windowWidth:600,_windowHeight:400});
}

Dimok.ProfilerAjax.prototype = {
  _getWindowBounds: function() {
    return new Sys.UI.Bounds(screenLeft, screenTop, document.documentElement.clientWidth, document.documentElement.clientHeight);
  },
  _getPosition: function() {
    arguments.callee.screenTop = screenTop;
    arguments.callee.screenLeft = screenLeft;
    status = "screenLeft:" + screenLeft;
  },
  _savePagePosition: function() {
    if (!this._isChildWindow()) return;
    var html = document.all.tags("HTML")[0];
    var box = this._getWindowBounds();
    var params = { pageName: this.get_pageType(), top: box.y, left: box.x, width: box.width, height: box.height };
    Dimok.Ajax({ methodName: "SavePagePosition", wsObject: WSA, global: false }, params);
  },
  _setPagePosition: function() {
    if (!this._isChildWindow()) return;
    var box = this._getWindowBounds();
    //var boxLast = Dimok.Ajax({ methodName: "GetPagePosition", wsObject: WSA, global: false }, [this.get_pageType()]);
    var xMoveBy = this.get_windowLeft() - box.x;
    var yMoveBy = this.get_windowTop() - box.y;
    var xResizeBy = this.get_windowWidth() - box.width;
    var yResizeBy = this.get_windowHeight() - box.height;
    resizeBy(xResizeBy, yResizeBy);
    setTimeout(function() { moveBy(xMoveBy, yMoveBy); }, 100);
  },
  initialize: function() {
    Dimok.ProfilerAjax.callBaseMethod(this, 'initialize');
    $J(window).one("beforeunload", null, Function.createDelegate(this, this._savePagePosition));
    this._setPagePosition();
  },
  dispose: function() {
    Dimok.ProfilerAjax.callBaseMethod(this, 'dispose');
  },
  _isChildWindow: function() {
    return window.opener || (typeof (window.dialogArguments) != "undefined");
  }
}
Dimok.ProfilerAjax.registerClass('Dimok.ProfilerAjax', motobankcorp.Component);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

//var html = document.all.tags("HTML")[0];
//var params = { pageName: this.get_pageType(), top: box.y, left: screenLeft, width: html.offsetWidth, height: html.offsetHeight };
